/*  ----------------------------------------------------------------------------
 *  Arello Mobile
 *  Fast 3d Engine
 *  ----------------------------------------------------------------------------
 * Except where otherwise noted, this work is licensed under
 * http://creativecommons.org/licenses/by/3.0
 */

#include "Sequence.h"
#include <logs/Log.h>

namespace liba
{
namespace lib2d
{
namespace objects
{

Sequence::Sequence()
:	loop_type( NONE ),
	frame_duration( 0.2f ),
	align_x( AX_LEFT ),
	align_y( AY_TOP ),
	frame_height( 0 ),
	frame_width( 0 ),
	frame_start( 0 ),
	frame_end( 0 )
{}

bool Sequence::on_attribute( xml::Provider * prov, const std::string & name, const std::string & value )
{
	if( name == "Name" )
	{
		logs::log() << "Name";
		this->name = Atom( value );
		return true;
	}
	if( name == "Image" )
	{
		logs::log() << "Image";
		image_name = value;
		return true;
	}

	if( name == "LoopType" )
	{
		logs::log() << "loop type";
		return converter::convert( value, &loop_type );
	}

	if( name == "FrameDuration" )
	{
		logs::log() << "duration";
		return converter::convert( value, &frame_duration );
	}

	if( name == "FrameHeight" )
	{
		logs::log() << "height";
		return converter::convert( value, &frame_height );
	}
	if( name == "FrameStart" )
	{
		logs::log() << "start";
		return converter::convert( value, &frame_start );
	}
	if( name == "FrameEnd" )
	{
		logs::log() << "end";
		return converter::convert( value, &frame_end );
	}

	if( name == "AlignX" )
	{
		return converter::convert( value, &align_x );
	}
	if( name == "AlignY" )
	{
		return converter::convert( value, &align_y );
	}

	return false;
}

bool Sequence::on_end_node( xml::Provider * prov )
{
	logs::log() << "On end node called";
	load_rep( ImageSequence::Param( image_name, frame_height ) );
	frame_width = get_rep()->get_width();
	return true;
}

converter::EnumPair<char, Sequence::LoopType> Sequence::LoopTypeNames[]=
{
	converter::MakeEnumPair( "NONE", Sequence::NONE ),
	converter::MakeEnumPair( "FORWARD", Sequence::FORWARD ),
	converter::MakeEnumPair( "PING_PONG", Sequence::PING_PONG ),
	0
};

converter::EnumPair<char, Sequence::AlignX> Sequence::AlignXNames[]=
{
	converter::MakeEnumPair( "AX_CENTER", Sequence::AX_CENTER ),
	converter::MakeEnumPair( "AX_LEFT", Sequence::AX_LEFT ),
	converter::MakeEnumPair( "AX_RIGHT", Sequence::AX_RIGHT ),
	0
};

converter::EnumPair<char, Sequence::AlignY> Sequence::AlignYNames[]=
{
	converter::MakeEnumPair( "AY_CENTER", Sequence::AY_CENTER ),
	converter::MakeEnumPair( "AY_TOP", Sequence::AY_TOP ),
	converter::MakeEnumPair( "AY_BOTTOM", Sequence::AY_BOTTOM ),
	0
};

} //namespace objects
} //namespace lib2d
} //namespace liba

